<?php $this->headLink()->prependStylesheet('http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.15/themes/base/jquery-ui.css');?>
<?php $this->headScript()->prependFile(Ac_Util::getImageBaseUrl('/js/admin_script.v-'.AC_VERSION.'.js'))?>
<?php $this->headScript()->prependFile('http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.10/jquery-ui.min.js')?>
<?php $this->JQuery()->javascriptCaptureStart() ?>
$(document).ready(function() {
    $('#translations input[type="text"]').each(function() {
        $(this).blur(function() {
            if ($(this).attr('prev') !== $(this).attr('value')) {
                $.post(
                    '<?php echo $this->geturl('edit','translate', null, 'admin1')?>',
                    {id:$(this).attr('rel'), val:escape($(this).attr('value')), loc:escape($(this).attr('locale'))}
                );
            }
        });
    });
});
<?php $this->JQuery()->javascriptCaptureEnd() ?>

<?php $this->headStyle()->captureStart()?>
    #content td { padding:5px}
    #content table { border:1px #aaa solid; padding:5px; width:100%}
    #content th {font-weight:bold;}
    #content .page a {padding:2px;}
    .range { width:100px; }
<?php $this->headStyle()->captureEnd()?>

<form method="get" name="listing_form">
    <a href="<?php echo $this->geturl('add','listing', null, 'admin1')?>">Add</a>
    Keyword : <input type="text" name="listing" id="search" value="<?php if (!empty($_GET['listing'])) { echo $_GET['listing']; }?>"/>
    <label for="from">From </label>
	<input type="text" id="from" name="from" class="range"/>
	<label for="to"> To </label>
	<input type="text" id="to" name="to" class="range"/>
    <input type="submit" name="search_btn" id="search_btn" value="Search"/>
    <?php if (!empty($_GET['listing'])) { ?>
        <a href="<?php echo $this->geturl('list','listing', null, 'admin1')?>">View All</a>
    <?php } ?>
</form>
<table border="1" id="listings">
<?php
    $get = $_GET; unset($get['page']);
    $pagination = $this->pagination($this->listing_number, $this->page, 15, 4, $this->geturl('list','listing', null, 'admin1', $get));
?>
<?php if($this->listing_number == 0):?>
	No Categories are defined
<?php else:?>
    <tr>
        <th>
            <a href="<?php echo $this->geturl('list','listing', null, 'admin1', array('sort'=> 'title', 'page' => $this->page))?>">Title</a>
        </th>
        <th>
            User
        </th>
        <th>
            <a href="<?php echo $this->geturl('list','listing', null, 'admin1', array('sort' => 'recent', 'page' => $this->page))?>">Creation date</a>
        </th>
        <th>
            <a href="<?php echo $this->geturl('list','listing', null, 'admin1', array('sort' => 'status', 'page' => $this->page))?>">Status</a>
        </th>
    </tr>
    <?php foreach ($this->list as $listing):?>
       <?php $item = Model_Listing::find($listing->id);?> 
        <tr>
            <td>
                <a href="<?php echo $this->geturl('display','listing', null, 'admin1', array('id'=> $item->id))?>" target="_blank">
                    <?php echo htmlentities($item->title, ENT_COMPAT, 'utf-8'); ?>
                </a>
            </td>
            <?php if (!empty($item->user)):?>
                <td>
                    U: <?php echo htmlentities((string)$item->user->username, ENT_COMPAT, 'utf-8'); ?>
                </td>
            <?php elseif(!empty($item->company)):?>
                <td>C: <?php echo htmlentities((string)$item->company->company_name, ENT_COMPAT, 'utf-8'); ?></td>
            <?php else:?>
                <td>&nbsp;</td>
            <?php endif;?>
            <td>
                <?php echo date (MEDIUM_DATE_FORMAT, $item->posted_at)?>
            </td>
            <td>
                <?php
                if ($item->status == Model_Listing::STATUS_PUBLISHED) {
                    echo 'Published';
                }
                if ($item->status == Model_Listing::STATUS_STARTED) {
                    echo 'Started';
                }
                if ($item->status == Model_Listing::STATUS_DRAFT) {
                    echo 'Draft';
                }
                if ($item->status == Model_Listing::STATUS_DELETED) {
                    echo 'Deleted';
                }
                if ($item->status == Model_Listing::STATUS_BANNED) {
                    echo 'Banned';
                }
                if ($item->status == Model_Listing::STATUS_MARK_SOLD) {
                    echo 'Marked as Sold';
                }
                if ($item->status == Model_Listing::STATUS_PUBLISHED_DELETED) {
	                echo 'PUBLISHED_DELETED';
	            }
                ?>
            </td>
        </tr>
    <?php 
    //echo "<pre>";print_r($item);echo "</pre>";
    endforeach; 
endif;
?>
</table>
<?php echo $pagination;?>
